package com.accp.biz.impl;

import java.util.List;


//import com.accp.dao.EmailDao;
//import com.accp.dao.VacationDao;
import com.accp.dao.UsersDao;
import com.accp.pojo.Users;
import com.accp.biz.UsersBiz;
/**
 * 用户业务实现类
 * @author Administrator
 *
 */
public class UsersBizImpl implements UsersBiz {
	private UsersDao usersDao;
//	private EmailDao emailDao;
//	private VacationDao vacationDao;
		
	public void setUsersDao(UsersDao usersDao) {
		this.usersDao = usersDao;
	}

//	public void setEmailDao(EmailDao emailDao) {
//		this.emailDao = emailDao;
//	}
//	
//	public void setVacationDao(VacationDao vacationDao) {
//		this.vacationDao = vacationDao;
//	}
	/**
	 * 用户登录
	 */
	public Users login(Users user) {
		List<Users> list=usersDao.login(user);
		if(list.size() >0){
			return list.get(0); 
		}
		return null;
	}
	/**
	 * 更新用户信息
	 */
	@Override
	public boolean update(Users user) {
		return usersDao.update(user);
	}
	/**
	 * 查找出自己以外的所有用户
	 */
	@Override
	public List<Users> findExceptMe(String userName) {
		List<Users> list=usersDao.findExceptMe(userName);
		return list;
	}
	/**
	 * 添加用户
	 */
	@Override
	public boolean add(Users user) {
		return usersDao.add(user);
	}
	/**
	 * 删除用户及其所有邮件和休假信息
	 */
	@Override
	public boolean deleteUser(Users user) {
		boolean flag = false;
		
//		String userName = user.getUserName();
//		System.out.println("得到的用户名为：\t"+userName);
//		if(emailDao.deleteAllByUser(userName) && vacationDao.deleteAllByUser(userName)){
//			usersDao.deleteUser(user);
//			flag = true;
//		}
		if(usersDao.deleteUser(user)){
			flag = true;
		}
		return flag;
	}
	/**
	 * 通过名字查找某个用户
	 */
	@Override
	public Users findByUserName(String userName) {
		return usersDao.findByUserName(userName);
	}
	/**
	 * 分页查询
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public List selectByPage(String className, int pageNo, int pageSize,String userName) {
		List list = usersDao.selectByPage(className, pageNo, pageSize,userName);
		return list;
	}
	/**
	 * 查看下一页
	 */
	@Override
	public int searchRecordsNextPage(int pageSize, String className,String userName) {
		int total = usersDao.totalPage(className,userName);
		int pageNo = total / pageSize;
		if(total % pageSize > 0){
			pageNo++;
		}
		return pageNo;
	}

}
